package com.syni.mdd.sjb.common.component.utils.common.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @className PatternUtils
 * @description 正则验证类
 * @Author cfx
 * @DATE 2019/5/13 15:37
 * @VERSION 1.0
 **/
public class PatternMatchUtils extends org.springframework.util.PatternMatchUtils {

    /**
     * 正则表达式：验证用户名
     */
    public static final String REGEX_USERNAME = "^[a-zA-Z]\\w{5,20}$";

    /**
     * 正则表达式：验证密码
     */
    public static final String REGEX_PASSWORD = "^[a-zA-Z0-9]{6,20}$";

    /**
     * 正则表达式：验证手机号
     */
    public static final String REGEX_MOBILE = "^[1](([3][0-9])|([4][5,7,9])|([5][^4])|([6][6])|([7][0,1,3,5,6,7,8])|([8][0-9])|([9][8,9]))[0-9]{8}$";

    /**
     * 正则表达式：验证邮箱
     */
    public static final String REGEX_EMAIL = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";

    /**
     * 正则表达式：验证汉字
     */
    public static final String REGEX_CHINESE = "^[\u4e00-\u9fa5],{0,}$";

    /**
     * 正则表达式：验证身份证
     */
    public static final String REGEX_ID_CARD = "(^\\d{18}$)|(^\\d{15}$)";

    /**
     * 正则表达式：验证URL
     */
    public static final String REGEX_URL = "http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?";

    /**
     * 正则表达式：验证IP地址
     */
    public static final String REGEX_IP_ADDR = "(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)";

    public static boolean checkPhone(String phone){
        return Pattern.matches(REGEX_MOBILE,phone);
    }
    public static boolean checkPassword(String password){
        return Pattern.matches(REGEX_PASSWORD,password);
    }
    public static boolean isNumeric(String str){

        Pattern pattern = Pattern.compile("[0-9]*");

        Matcher isNum = pattern.matcher(str);

        if( !isNum.matches() ){
            return false;

        }
        return true;
    }

    public static boolean checkIsEnglish(String str) {
        Pattern pattern = Pattern.compile("[a-zA-Z0-9]+");

        Matcher isEnglish = pattern.matcher(str);

        return isEnglish.matches();
    }
}
